<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>支出列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="__TMPL__/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="__TMPL__/css/admin.css" media="all">
	<script type="text/javascript" src="__TMPL__/js/jquery.min.js"></script>
	<script type="text/javascript" src="__TMPL__/layui/layui.js"></script>
	<script type="text/javascript" src="__TMPL__/js/admin.js"></script>
    <script type="text/javascript" src="__TMPL__/layui/lay/modules/util.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <select name="department_id" lay-filter="required">
                            <option value="">请选择部门</option>
                            <volist name="department_list" id="vo">
                                <option value="{$key}">{$vo}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="width: 200px">
                    <div class="layui-input-inline">
                        <input type="text" name="time" id="time" placeholder="选择时间" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit="" lay-filter="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
<!--                <div class="layui-inline">-->
<!--                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="month">-->
<!--                        近一月-->
<!--                    </button>-->
<!--                </div>-->
<!--                <div class="layui-inline">-->
<!--                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="month_3">-->
<!--                        近三月-->
<!--                    </button>-->
<!--                </div>-->
            </div>
        </div>
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
            <script type="text/html" id="toolbar">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="add">
                        <span>添加</span>
                    </button>
                </div>
            </script>
            <script type="text/html" id="status">
                {{# if(d.status == 0){ }}
                <button class="layui-btn layui-btn-xs" >正常</button>
                {{# }else if(d.status == 1){ }}
                <button class="layui-btn layui-btn-xs" >正常</button>
                {{# } }}
            </script>

            <script type="text/html" id="option">
                <button class="layui-btn layui-btn-sm layui-btn-normal" type="button" lay-event="edit">
                    编辑
                </button>
            </script>
            <script type="text/html" id="expend_time">
                {{ time2date(d.expend_time) }}
            </script>
        </div>
    </div>
</div>
<script type="text/html" id="check">
    <input type="radio" name="layTableCheckbox" value="{{d.id}}" lay-filter="check">
</script>
<script>
    layui.config({
        base: '__TMPL__/public/', //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['layer', 'table', 'form','laydate'], function () {
        var table       = layui.table,
            layer       = layui.layer,
            form        = layui.form,
            admin       = layui.admin,
            laydate = layui.laydate;

        laydate.render({
            elem: '#time',
            range: true,
        });
        form.on('submit(search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('dataTable', {
                where: field
            });
        });

        form.on('submit(add)', function(data){
            var index = layer.open({
                type: 2
                ,title: '添加支出'
                ,content: "/admin/expend/operate"
                ,maxmin: true
                ,area: ['700px', '560px']
                ,btn: ['确定', '取消']
                ,yes: function(index, layero){
                    var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                    submit.click();
                }
            });
            //layer.full(index);
        });
        //用户表格初始化
        var dataTable = table.render({
            elem: '#dataTable'
            , url: "{:url('Expend/data')}" //数据接口
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter', 'exports', 'print']
            , page: true //开启分页
            , response: {
                statusCode: 1
            }
            , cols: [[ //表头
                {checkbox: true, fixed: true}
                ,{field: 'employee', title: "姓名"}
                , {field: 'expend_time', title: "支出时间",width:200}
                , {field: 'money', title: "金额"}
                , {field: 'use_name', title: "用途"}
                , {field: 'department', title: "部门"}
                , {field: 'remark', title: "备注"}
                , {field: 'status', title: "状态", toolbar: '#status'}
                , {title: "操作", toolbar: '#option'}
            ]]
        });
        table.on('toolbar(dataTable)', function(obj){
            switch(obj.event){
                case 'add':
                    var index = layer.open({
                        type: 2
                        ,title: '添加支出'
                        ,content: "/admin/expend/operate"
                        ,maxmin: true
                        ,area: ['700px', '560px']
                        ,btn: ['确定', '取消']
                        ,yes: function(index, layero){
                            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                            submit.click();
                        }
                    });
                    //layer.full(index);
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(dataTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    type: 2
                    ,title: '编辑支出'
                    ,content: "/admin/expend/operate?expend_id="+data.id
                    ,maxmin: true
                    ,area: ['700px', '560px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
                //layer.full(index);
            }
        });
    });
    function time2date(t) {
        var t1 = parseInt(t + '000');
        return layui.util.toDateString(t1, "yyyy-MM-dd");
    }
</script>
</body>
</html>